package com.wang.template.json.util;

import java.lang.annotation.Annotation;
import java.util.Map;

import org.apache.commons.lang3.ArrayUtils;

import com.wang.template.json.asm.ASMAccess;
import com.wang.template.json.asm.MethodAccess;
import com.wang.template.json.asm.ProxyFactory;
import com.wang.template.json.core.MethodCache;

/**
 * 表达式扩类</br>
 * 经常开发中需要用某个工具方法返回一个字段
 * 
 * @author wangxinlin
 *
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public class UtilExt {
	private static Map<String, MethodAccess> methodCache = MethodCache.getInstance().getMethodCache();

	public static void addMethodAccess(Class... classArray) throws Exception {
		if (ArrayUtils.isNotEmpty(classArray)) {
			for (Class clazz : classArray) {
				Annotation ann = clazz.getAnnotation(ASMAccess.class);
				MethodAccess methodAccess = (MethodAccess) ProxyFactory.createrProxyBean(clazz).newInstance();
				if (ann != null) {
					ASMAccess asm = (ASMAccess) ann;
					methodCache.put(asm.name(), methodAccess);
				} else {
					methodCache.put(clazz.getName(), methodAccess);
				}
			}
		}
	}
}
